<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="baidu-site-verification" content="zD47G9xe42" />


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux," />





  <link rel="alternate" href="/atom.xml" title="uiste" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="Linux目录结构bin 和 sbin  ：存放命令的/dev        ：存放外设文件/etc        ：存放配置文件/home       ：普通用户的家目录(主目录)/root       ：超级管理员的家目录/mnt        ：挂载点/usr        ：安装程序/var        ：相当于D、E盘，用来存储一些文件站点
Linux常用命令passwd    更改密">
<meta property="og:type" content="article">
<meta property="og:title" content="初识Linux">
<meta property="og:url" content="http://blog.uiste.com/20160924-2.html">
<meta property="og:site_name" content="uiste">
<meta property="og:description" content="Linux目录结构bin 和 sbin  ：存放命令的/dev        ：存放外设文件/etc        ：存放配置文件/home       ：普通用户的家目录(主目录)/root       ：超级管理员的家目录/mnt        ：挂载点/usr        ：安装程序/var        ：相当于D、E盘，用来存储一些文件站点
Linux常用命令passwd    更改密">
<meta property="og:image" content="http://blog.uiste.com/media/14746901645222/14746929569559.jpg">
<meta property="og:updated_time" content="2016-10-04T10:43:23.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="初识Linux">
<meta name="twitter:description" content="Linux目录结构bin 和 sbin  ：存放命令的/dev        ：存放外设文件/etc        ：存放配置文件/home       ：普通用户的家目录(主目录)/root       ：超级管理员的家目录/mnt        ：挂载点/usr        ：安装程序/var        ：相当于D、E盘，用来存储一些文件站点
Linux常用命令passwd    更改密">
<meta name="twitter:image" content="http://blog.uiste.com/media/14746901645222/14746929569559.jpg">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://blog.uiste.com/20160924-2.html"/>

  <title>
 初识Linux | uiste 
</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?b58b87af012832b8ae35e33bb45b44fa";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">uiste</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">uiste个人博客</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      

            <li class="menu-item menu-item-search"> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
    function c() {
        var e = document.createElement("link");
        e.setAttribute("type", "text/css");
        e.setAttribute("rel", "stylesheet");
        e.setAttribute("href", f);
        e.setAttribute("class", l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement("div");
        e.setAttribute("class", a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement("audio");
        e.setAttribute("class", l);
        e.src = i;
        e.loop = false;
        e.addEventListener("canplay", function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener("ended", function() {
            N();
            h()
        }, true);
        e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += " " + s + " " + o
    }
 
    function T(e) {
        e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp("\\b" + s + "\\b");
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, "")
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
    var s = "mw-harlem_shake_me";
    var o = "im_first";
    var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    var a = "mw-strobe_light";
    var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    var l = "mw_added_css";
    var b = g();
    var w = y();
    var C = document.getElementsByTagName("*");
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn("Could not find a node of the right size. Please try a different page.");
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()    '>High</a> </li>

    </ul>
  

 
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
   
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                初识Linux
              
            
          </h1>
        

        <div class="post-meta">
        
  <span id="busuanzi_container_page_pv">阅读量 <span id="busuanzi_value_page_pv"></span> 次</span>

          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-24T14:06:41+08:00" content="2016-09-24">
              2016-09-24
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160924-2.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160924-2.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Linux目录结构"><a href="#Linux目录结构" class="headerlink" title="Linux目录结构"></a>Linux目录结构</h2><p>bin 和 sbin  ：存放命令的<br>/dev        ：存放外设文件<br>/etc        ：存放配置文件<br>/home       ：普通用户的家目录(主目录)<br>/root       ：超级管理员的家目录<br>/mnt        ：挂载点<br>/usr        ：安装程序<br>/var        ：相当于D、E盘，用来存储一些文件站点</p>
<h2 id="Linux常用命令"><a href="#Linux常用命令" class="headerlink" title="Linux常用命令"></a>Linux常用命令</h2><p>passwd    更改密码<br>ls    、ls -al *.png    查看目录中的内容<br>cd    进入目录<br>exit    退出当前工作环境<br>pwd    获取当前工作目录<br>su或su -    获取管理员权限<br>su - uiste    获取普通用户的权限<br>runlevel    获取运行级别<br>init N    改变运行等级<br>startx 和init5    启动图形化界面<br>clear    清空终端</p>
<h2 id="Linux命令格式"><a href="#Linux命令格式" class="headerlink" title="Linux命令格式"></a>Linux命令格式</h2><p>语法：名利 [-选项] 参数<br>Linux 命令是区分大小写的</p>
<h2 id="查看文件的详细信息-ls-al"><a href="#查看文件的详细信息-ls-al" class="headerlink" title="查看文件的详细信息(ls -al)"></a>查看文件的详细信息(ls -al)</h2><p>-a  显示所有文件<br>-l  显示详细信息<br><img src="media/14746901645222/14746929569559.jpg" alt=""><br>pwd    显示当前目录<br>ls    显示当前目录的文件<br>ls -l    列出文件的详细信息<br>ls -a    列出所有文件，包括隐藏文件<br>ls -al    后面是查询选择，查询选项是没有先后顺序的</p>
<h2 id="常用指令"><a href="#常用指令" class="headerlink" title="常用指令"></a>常用指令</h2><p>dir             显示当前目录的所有文件<br>who am  i       显示登录的用户名<br>whoami          显示当前使用谁的权限<br>exit  、q        退出权限系统<br>halt            关闭计算机<br>power off       关闭计算机<br>reboot          重启计算机<br>man             查看帮助文档 manual<br>–help、-help    调用命令的注释帮助</p>
<h2 id="显示目录所占磁盘容量-du"><a href="#显示目录所占磁盘容量-du" class="headerlink" title="显示目录所占磁盘容量(du)"></a>显示目录所占磁盘容量(du)</h2><p>du file/dir 显示文件或文件夹的容量，单位是KB，如果是文件夹显示文件夹中每个文件额大小和总大小<br>du -s dir 显示文件夹的总大小，不显示文件夹中文件大小<br>du -h file/dir 用友好的方式显示容量</p>
<h2 id="改变工作目录-cd"><a href="#改变工作目录-cd" class="headerlink" title="改变工作目录(cd)"></a>改变工作目录(cd)</h2><p>语法：cd 目录</p>
<table>
<thead>
<tr>
<th>cd dir</th>
<th>进入dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>cd ..</td>
<td>..表示上一级</td>
</tr>
<tr>
<td>cd ../dir</td>
<td>进入上一级目录中的dir文件夹下</td>
</tr>
<tr>
<td>cd /dir</td>
<td>通过绝对路径进入到dir文件夹下</td>
</tr>
<tr>
<td>cd ~</td>
<td>进入个人主目录</td>
</tr>
<tr>
<td>cd</td>
<td>cd后面不跟参数就进入到个人主目录，和cd ~一样</td>
</tr>
</tbody>
</table>
<h2 id="目录操作"><a href="#目录操作" class="headerlink" title="目录操作"></a>目录操作</h2><h3 id="创建目录-mkdir"><a href="#创建目录-mkdir" class="headerlink" title="创建目录(mkdir)"></a>创建目录(mkdir)</h3><table>
<thead>
<tr>
<th>mkdir dir1</th>
<th>在当前目录下创建dir1文件夹</th>
</tr>
</thead>
<tbody>
<tr>
<td>mkdir dir1/dir2</td>
<td>在dir1目录下创建dir2目录（dir1必须存在)</td>
</tr>
<tr>
<td>mkdir -p dir1/dir2</td>
<td>如果没有dir1，先创建dir1再创建dir2. -p 可以写在后面</td>
</tr>
<tr>
<td>mk dir1 dir2 .</td>
<td>同时创建dir1、dir2、dir3…</td>
</tr>
</tbody>
</table>
<h3 id="删除目录-rmdir"><a href="#删除目录-rmdir" class="headerlink" title="删除目录(rmdir)"></a>删除目录(rmdir)</h3><table>
<thead>
<tr>
<th>rmdir dir</th>
<th>删除目录，如果目标不为空这报错，不能删除</th>
</tr>
</thead>
<tbody>
<tr>
<td>rmdir dir1 dir2</td>
<td>同时删除多个目录</td>
</tr>
</tbody>
</table>
<h3 id="既能删除文件也能删除目录-rm"><a href="#既能删除文件也能删除目录-rm" class="headerlink" title="既能删除文件也能删除目录(rm)"></a>既能删除文件也能删除目录(rm)</h3><blockquote>
<p>-r recursieve 递归<br>-f force 强制</p>
</blockquote>
<table>
<thead>
<tr>
<th>rm file</th>
<th>删除文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>rm -rf file/dir</td>
<td>删除文件和文件夹</td>
</tr>
</tbody>
</table>
<h2 id="复制文件和目录-cp"><a href="#复制文件和目录-cp" class="headerlink" title="复制文件和目录(cp)"></a>复制文件和目录(cp)</h2><p>语法：cp [-r/-R] 源地址 目标地址</p>
<table>
<thead>
<tr>
<th>cp file dir</th>
<th>将file文件拷贝到dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>cp file1 dir/file2</td>
<td>将file1拷贝到dir文件夹下并改名为file2</td>
</tr>
<tr>
<td>cp file1 file2</td>
<td>将file1复制一份，重命名为file2</td>
</tr>
<tr>
<td>cp -R/-r dir1 dir2</td>
<td>将dir1文件夹递归复制到dir2文件夹下</td>
</tr>
</tbody>
</table>
<h2 id="移动文件或目录-mv"><a href="#移动文件或目录-mv" class="headerlink" title="移动文件或目录(mv)"></a>移动文件或目录(mv)</h2><table>
<thead>
<tr>
<th>mv file dir</th>
<th>将file文件移动到dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>mv dir1 dir2</td>
<td>dir2不存在就是该文件夹名字 dir2存在就是将dir1移动到dir2文件夹下</td>
</tr>
<tr>
<td>mv file1 file2</td>
<td>将file1的名字改为file2</td>
</tr>
<tr>
<td>mv dir1 dir2/dir3</td>
<td>将dir1拷贝到dir2文件夹下，并改名为dir3</td>
</tr>
</tbody>
</table>
<h2 id="文件查看"><a href="#文件查看" class="headerlink" title="文件查看"></a>文件查看</h2><table>
<thead>
<tr>
<th>cat 文件名</th>
<th>一次性查看全部内容</th>
</tr>
</thead>
<tbody>
<tr>
<td>more 文件名</td>
<td>分屏显示，按回车向下翻，一旦下翻就不能上翻</td>
</tr>
<tr>
<td>less 文件名</td>
<td>允许上翻和下翻，按向上和向下的键</td>
</tr>
<tr>
<td>head -n 文件名</td>
<td>显示前n条记录</td>
</tr>
<tr>
<td>tail -n 文件名</td>
<td>显示后几条</td>
</tr>
<tr>
<td>wc 文件名</td>
<td>用来计算文件行数、句数、字符数</td>
</tr>
</tbody>
</table>
<h2 id="新建文件和添加内容"><a href="#新建文件和添加内容" class="headerlink" title="新建文件和添加内容"></a>新建文件和添加内容</h2><h3 id="新建文件-touch"><a href="#新建文件-touch" class="headerlink" title="新建文件(touch)"></a>新建文件(touch)</h3><table>
<thead>
<tr>
<th>touch 文件名</th>
<th>新建一个文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>touch file1 file2 …</td>
<td>一次新建多个文件</td>
</tr>
<tr>
<td>touch dir/file</td>
<td>在dir文件夹下新建file文件</td>
</tr>
</tbody>
</table>
<h3 id="添加内容-echo、cat"><a href="#添加内容-echo、cat" class="headerlink" title="添加内容(echo、cat)"></a>添加内容(echo、cat)</h3><table>
<thead>
<tr>
<th>echo 内容&gt;文件</th>
<th>将内容写入到文件（清空写），如果文件不存在则创建新文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>echo 内容&gt;&gt;文件</td>
<td>和上面一样，（追加内容）</td>
</tr>
<tr>
<td>cat file1&gt;file2</td>
<td>将file1的内容写到file2中（清空写）（文件不存在则创建）</td>
</tr>
<tr>
<td>cat file1&gt;&gt;file2</td>
<td>和上面一样，（追加内容）</td>
</tr>
<tr>
<td>cat file1 file2 &gt; file3</td>
<td>将file1和file2的内容合并成file3</td>
</tr>
</tbody>
</table>
<blockquote>
<p>>是清空写<br>>&gt;追加写<br>写入&gt;字符时，使用引号，或者\ 反斜杠，进行转义</p>
</blockquote>
<h2 id="组-group-的操作"><a href="#组-group-的操作" class="headerlink" title="组(group)的操作"></a>组(group)的操作</h2><table>
<thead>
<tr>
<th>groupadd 组名</th>
<th>添加组</th>
</tr>
</thead>
<tbody>
<tr>
<td>grouped -n 新组名 旧组名</td>
<td>修改组</td>
</tr>
<tr>
<td>grouped 组名</td>
<td>删除组</td>
</tr>
</tbody>
</table>
<blockquote>
<p>查看组：cat ../etc/group</p>
</blockquote>
<h2 id="用户（user）的操作"><a href="#用户（user）的操作" class="headerlink" title="用户（user）的操作"></a>用户（user）的操作</h2><blockquote>
<p>用户信息都保存在<code>/etc/passwd</code> 文件中 <code>cat ../etc/passwd</code><br><code>uiste:x:500:500::/home/uiste:/bin/bash</code><br>用户名：口令：用户id号：组的id号：注释性描述：家目录：登录shell</p>
</blockquote>
<h3 id="添加用户（useradd）"><a href="#添加用户（useradd）" class="headerlink" title="添加用户（useradd）"></a>添加用户（useradd）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>useradd 用户名</td>
<td>创建用户，在创建的时候自动创建组</td>
</tr>
<tr>
<td>useradd 用户名 -g 组编号</td>
<td>在相应的组下创建用户</td>
</tr>
<tr>
<td>useradd 用户名 -u 用户编号</td>
<td>给创建的用户指定用户编号</td>
</tr>
<tr>
<td>useradd 用户名 -d 家目录</td>
<td>给用户指定家目录</td>
</tr>
</tbody>
</table>
<h3 id="修改用户（usermod）"><a href="#修改用户（usermod）" class="headerlink" title="修改用户（usermod）"></a>修改用户（usermod）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>usermod -l 新用户名 旧用户名</td>
<td>修改用户名</td>
</tr>
<tr>
<td>usermod -u 用户编号 用户名</td>
<td>修改用户编号</td>
</tr>
<tr>
<td>usermod -g 组的编号 用户名</td>
<td>修改用户的组</td>
</tr>
<tr>
<td>usermod -d 家目录 用户名</td>
<td>修改家目录</td>
</tr>
</tbody>
</table>
<h3 id="删除用户（userdel）"><a href="#删除用户（userdel）" class="headerlink" title="删除用户（userdel）"></a>删除用户（userdel）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>userdel 用户名</td>
<td>删除用户，家目录还存在</td>
</tr>
<tr>
<td>userdel -r 用户名</td>
<td>删除用户同时删除家目录</td>
</tr>
</tbody>
</table>
<h2 id="常用指令-1"><a href="#常用指令-1" class="headerlink" title="常用指令"></a>常用指令</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>grep string [file]</td>
<td>在字符串中查找</td>
</tr>
<tr>
<td>ps -A</td>
<td>（process）查询所有进程</td>
</tr>
<tr>
<td>kill —9 pid</td>
<td>杀死指定进程</td>
</tr>
<tr>
<td>df -lh</td>
<td>参看系统分区</td>
</tr>
</tbody>
</table>
<h2 id="date"><a href="#date" class="headerlink" title="date"></a>date</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>date</td>
<td>显示系统时间</td>
</tr>
<tr>
<td>date -s ‘2015-11-6 11:11:11’</td>
<td>更改系统时间</td>
</tr>
</tbody>
</table>
<h2 id="管道"><a href="#管道" class="headerlink" title="管道(|)"></a>管道(|)</h2><h2 id="查找文件（find）"><a href="#查找文件（find）" class="headerlink" title="查找文件（find）"></a>查找文件（find）</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>find / -name passwd</td>
<td>查找根下所有passwd的文件[区分大小写]</td>
</tr>
<tr>
<td>find / -iname passwd</td>
<td>查找根下所有passwd的文件[不区分大小写]</td>
</tr>
<tr>
<td>find / -mindepth 3 -name passwd</td>
<td>在最低3层目录下查找passwd文件</td>
</tr>
<tr>
<td>find / -maxdepth 2 -name passwd</td>
<td>在最高2层目录下查找passwd文件</td>
</tr>
<tr>
<td>find . -iname *.c</td>
<td>在当前目录下查找以.c结尾的文件，不区分大小写</td>
</tr>
<tr>
<td>find / -size +50k</td>
<td>搜索大于50K的文件</td>
</tr>
<tr>
<td>find / -size -40c</td>
<td>搜索小鱼40字节的文件char</td>
</tr>
<tr>
<td>find . -type f</td>
<td>查找当前目录下的所有文件</td>
</tr>
<tr>
<td>find . -type d</td>
<td>查找当前目录下所有的文件夹</td>
</tr>
</tbody>
</table>
<h2 id="软连接和硬连接"><a href="#软连接和硬连接" class="headerlink" title="软连接和硬连接"></a>软连接和硬连接</h2><h3 id="软连接"><a href="#软连接" class="headerlink" title="软连接"></a>软连接</h3><p>软连接就是快捷方式<br>语法：ln -s 源文件 连接文件</p>
<h3 id="硬连接"><a href="#硬连接" class="headerlink" title="硬连接"></a>硬连接</h3><p>语法：ln 源文件 连接文件<br>查看：ls -li 查看文件的索引编号</p>
<blockquote>
<p>在Linux中删除文件并不是件文件本身删除，而是删除文件的索引，文件是垃圾回收机制来删除<br>只有文件才能做硬连接</p>
</blockquote>
<h2 id="权限（rwx-）"><a href="#权限（rwx-）" class="headerlink" title="权限（rwx-）"></a>权限（rwx-）</h2><p>Linux的权限有3种：读权限（read）、写权限（write）、可执行权限（execute）<br>文件属性部分有10个字符组成，第一个字符是表示文件的类型，后面还剩下9个字符，每3个一组（每组由读、写、可执行组成），分成3组，第一组是文件所有者（user）的权限，第二组是和文件所有者同组（group）的权限，第三组其他用户（other）的权限</p>
<h3 id="常用便是文件的字符"><a href="#常用便是文件的字符" class="headerlink" title="常用便是文件的字符"></a>常用便是文件的字符</h3><table>
<thead>
<tr>
<th>b</th>
<th>系统设备文件，使用i/o与外界交互的设备，通常是磁盘</th>
</tr>
</thead>
<tbody>
<tr>
<td>d</td>
<td>表示文件夹</td>
</tr>
<tr>
<td>-</td>
<td>表示文件</td>
</tr>
<tr>
<td>l</td>
<td>连接文件</td>
</tr>
<tr>
<td>c</td>
<td>系统设备文件，利用串口设备和声音</td>
</tr>
</tbody>
</table>
<h3 id="更新权限"><a href="#更新权限" class="headerlink" title="更新权限"></a>更新权限</h3><p>语法：chmod 权限 file/dir</p>
<table>
<thead>
<tr>
<th>案例</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>chmod u+x,o+rx dir</td>
<td>用户添加可执行权限，其他用户添加读、可执行权限</td>
</tr>
<tr>
<td>chmod u+rwx,o-r file</td>
<td>用户添加读、写、可执行，其他用户去掉读权限</td>
</tr>
<tr>
<td>chmod go -rwx file</td>
<td>组和其他用户去掉读、写、可执行权限</td>
</tr>
<tr>
<td>chmod 750 file</td>
<td>通过数字来设置权限</td>
</tr>
</tbody>
</table>
<h2 id="更改文件所有者和组"><a href="#更改文件所有者和组" class="headerlink" title="更改文件所有者和组"></a>更改文件所有者和组</h2><h3 id="更改所有者（chown）"><a href="#更改所有者（chown）" class="headerlink" title="更改所有者（chown）"></a>更改所有者（chown）</h3><table>
<thead>
<tr>
<th>chown user file</th>
<th>将file改成user用户</th>
</tr>
</thead>
<tbody>
<tr>
<td>chown -R user dir</td>
<td>将dir文件中的所有文件所有者改为user</td>
</tr>
</tbody>
</table>
<h3 id="更改组（chgrp）"><a href="#更改组（chgrp）" class="headerlink" title="更改组（chgrp）"></a>更改组（chgrp）</h3><p>语法一：chgrp [-R] 新组名 file/dir<br>将file 或 dir 更改新组名<br>语法二：chown 用户名.组名 文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">chown  user passwd        将passwd更改为user所有</div><div class="line">chown  .php passwd        将passwd更改为php组所有</div><div class="line">chown  user.php passwd    将passwd更改为php组的user所有</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux/" rel="tag">#Linux</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/20160924-1.html" rel="next" title="Vim（VI）">
                <i class="fa fa-chevron-left"></i> Vim（VI）
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/20160926-1.html" rel="prev" title="COOKIE 和 SESSION">
                COOKIE 和 SESSION <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- Go to www.addthis.com/dashboard to customize your tools -->
<script type = "text/javascript" src = "//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-57838eee5e2620d0" async = "async" ></script>
      
    </div>
  </div>


          </div>
          

  <p>热评文章</p>
  <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="20160924-2.html"
           data-title="初识Linux" data-url="http://blog.uiste.com/20160924-2.html">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="uiste" />
          <p class="site-author-name" itemprop="name">uiste</p>
          <p class="site-description motion-element" itemprop="description">Stay Hungry，Stay Foolish</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">55</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/uiste" target="_blank" rel="external nofollow" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/uiste" target="_blank" rel="external nofollow" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/uiste" target="_blank" rel="external nofollow" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.uiste.com" title="uiste 个人博客" target="_blank">uiste 个人博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://uiste.github.io" title="uiste 技术博客" target="_blank">uiste 技术博客</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux目录结构"><span class="nav-number">1.</span> <span class="nav-text">Linux目录结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux常用命令"><span class="nav-number">2.</span> <span class="nav-text">Linux常用命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux命令格式"><span class="nav-number">3.</span> <span class="nav-text">Linux命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看文件的详细信息-ls-al"><span class="nav-number">4.</span> <span class="nav-text">查看文件的详细信息(ls -al)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常用指令"><span class="nav-number">5.</span> <span class="nav-text">常用指令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#显示目录所占磁盘容量-du"><span class="nav-number">6.</span> <span class="nav-text">显示目录所占磁盘容量(du)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#改变工作目录-cd"><span class="nav-number">7.</span> <span class="nav-text">改变工作目录(cd)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#目录操作"><span class="nav-number">8.</span> <span class="nav-text">目录操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建目录-mkdir"><span class="nav-number">8.1.</span> <span class="nav-text">创建目录(mkdir)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除目录-rmdir"><span class="nav-number">8.2.</span> <span class="nav-text">删除目录(rmdir)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#既能删除文件也能删除目录-rm"><span class="nav-number">8.3.</span> <span class="nav-text">既能删除文件也能删除目录(rm)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#复制文件和目录-cp"><span class="nav-number">9.</span> <span class="nav-text">复制文件和目录(cp)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#移动文件或目录-mv"><span class="nav-number">10.</span> <span class="nav-text">移动文件或目录(mv)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文件查看"><span class="nav-number">11.</span> <span class="nav-text">文件查看</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#新建文件和添加内容"><span class="nav-number">12.</span> <span class="nav-text">新建文件和添加内容</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#新建文件-touch"><span class="nav-number">12.1.</span> <span class="nav-text">新建文件(touch)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#添加内容-echo、cat"><span class="nav-number">12.2.</span> <span class="nav-text">添加内容(echo、cat)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组-group-的操作"><span class="nav-number">13.</span> <span class="nav-text">组(group)的操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#用户（user）的操作"><span class="nav-number">14.</span> <span class="nav-text">用户（user）的操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#添加用户（useradd）"><span class="nav-number">14.1.</span> <span class="nav-text">添加用户（useradd）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改用户（usermod）"><span class="nav-number">14.2.</span> <span class="nav-text">修改用户（usermod）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除用户（userdel）"><span class="nav-number">14.3.</span> <span class="nav-text">删除用户（userdel）</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常用指令-1"><span class="nav-number">15.</span> <span class="nav-text">常用指令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#date"><span class="nav-number">16.</span> <span class="nav-text">date</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#管道"><span class="nav-number">17.</span> <span class="nav-text">管道(|)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查找文件（find）"><span class="nav-number">18.</span> <span class="nav-text">查找文件（find）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#软连接和硬连接"><span class="nav-number">19.</span> <span class="nav-text">软连接和硬连接</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#软连接"><span class="nav-number">19.1.</span> <span class="nav-text">软连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#硬连接"><span class="nav-number">19.2.</span> <span class="nav-text">硬连接</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#权限（rwx-）"><span class="nav-number">20.</span> <span class="nav-text">权限（rwx-）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#常用便是文件的字符"><span class="nav-number">20.1.</span> <span class="nav-text">常用便是文件的字符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#更新权限"><span class="nav-number">20.2.</span> <span class="nav-text">更新权限</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#更改文件所有者和组"><span class="nav-number">21.</span> <span class="nav-text">更改文件所有者和组</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#更改所有者（chown）"><span class="nav-number">21.1.</span> <span class="nav-text">更改所有者（chown）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#更改组（chgrp）"><span class="nav-number">21.2.</span> <span class="nav-text">更改组（chgrp）</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">uiste</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io" rel="external nofollow">Hexo</a> 趋势动力
</div>
<!--站长统计-->
<script src="https://s95.cnzz.com/z_stat.php?id=1259894121&web_id=1259894121" language="JavaScript"></script>
<!--<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next" rel="external nofollow">
    NexT.Mist
  </a>
</div> -->
&nbsp;&nbsp;&nbsp;本站总点击 <span id="busuanzi_value_site_pv"></span> 次
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;您是第 <span id="busuanzi_value_site_uv"></span> 位访客

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"uiste"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

</body>
</html>
